﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace MaymuseMS.Models {
    public class MaymuseMSContext : DbContext {
        public DbSet<Product> Products { get; set; }
        public DbSet<Parts> Parts { get; set; }
        public DbSet<Semifinished> Semifinisheds { get; set; }
        public DbSet<Finished> Finisheds { get; set; }

        public DbSet<Configuration> Configurations { get; set; }
        public DbSet<ConfigurationItem> ConfigurationItems { get; set; }

        public DbSet<Supplier> Suppliers { get; set; }
        public DbSet<SupplierUser> SupplierUsers { get; set; }
        public DbSet<ProductItem> ProductItems { get; set; }

        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderItem> OrderItems { get; set; }

        public DbSet<InDepository> InDepositories { get; set; }
        public DbSet<PartsInDepository> PartsInDepositories { get; set; }
        public DbSet<SemifinishedInDepository> SemifinishedInDepositories { get; set; }
        public DbSet<FinishedInDepository> FinishedInDepositories { get; set; }
        public DbSet<ProduceOrder> ProduceOrders { get; set; }

        public DbSet<OutDepository> OutDepositories { get; set; }
        public DbSet<PartsOutDepository> PartsOutDepositories { get; set; }
        public DbSet<SemifinishedOutDepository> SemifinishedOutDepositories { get; set; }
        public DbSet<FinishedOutDepository> FinishedOutDepositories { get; set; }

        public DbSet<Depository> Depositories { get; set; }
        public DbSet<DepositoryItem> DepositoryItems { get; set; }
        public DbSet<PartsDepository> PartsDepositories { get; set; }
        public DbSet<SemifinishedDepository> SemifinishedDepositories { get; set; }
        public DbSet<FinishedDepository> FinishedDepositories { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder) {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Entity<Configuration>()
                .HasRequired(c => c.Product)
                .WithMany()
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<ConfigurationItem>()
                .HasRequired(c => c.Product)
                .WithMany()
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<Order>()
                .HasRequired(c => c.Supplier)
                .WithMany()
                .WillCascadeOnDelete(false);
            modelBuilder.Entity<Order>()
                .HasRequired(c => c.SupplierUser)
                .WithMany()
                .WillCascadeOnDelete(false);
            
        }
    }
}